const fs = require('fs');
const path = require('path');

const readPath = path.join(__dirname, 'assets/error_code.txt');
const outPath = path.join(__dirname, 'out/error_code.json');

fs.readFile(readPath, 'utf-8', (err, data) => {
    if (err) {
        console.error(err);
        return;
    } 
    const lines = data.split('\n').map(line=> line.trim()).filter(line=> line.length > 0);
      const jsonData = lines.map((item, index)=> {
        const [code, message] = item.split('\t');
        return {
          code: Number(code),
          msg: message
        }
      })
      fs.writeFile(outPath, JSON.stringify(jsonData, null, 2), (err) => {
        if (err) {
            console.error(err);
            return;
        }
        console.log('JSON文件已保存');
      });
});